import Vue from 'vue'
import Vuex from 'vuex'

//安装 ：cnpm i vuex-persist --save-dev
import vuexPersist from "vuex-persist";
//引入 vuex 持久化插件
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    stdata: [],
  },
  mutations: {
    ddd(state, item) {
      var flag = false;
      state.stdata.forEach((i) => {
        if (i.name == item.name) {
          flag = true;
        }
      });
      if (flag == false) {
        state.stdata.push(item);
      }
    },
    close(state, item) {
      state.stdata.forEach((t,index) => {
        if (t.name == item.name) {
          state.stdata.splice(index,1);
        }
      });
    }
  },
  actions: {},
  modules: {},
  getters: {},
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ]
})